﻿import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.12
import QtMultimedia

Window {
    visible: true

    color: "transparent"
    flags: Qt.FramelessWindowHint | Qt.Window | Qt.WA_TranslucentBackground//| Qt.Window   | Qt.X11BypassWindowManagerHint
    visibility: Window.Maximized
    property int counter: 0
        Column {
            anchors.centerIn: parent
            //spacing: 30 // 文字与图片之间的间距

            Text {
                id: myText
                text: "功德+1"
                visible: false
                opacity: 1.0
                font.pointSize: 12
                color:"#001d26"
                wrapMode: Text.WordWrap
                width: parent.width
                horizontalAlignment: Text.AlignHCenter
                x:myImage.x
                y:myImage.y - 50
            }

            SequentialAnimation {
                        id: moveAndFadeOut
                        running: false

                        NumberAnimation {
                            target: myText
                            property: "y"
                            from: myImage.y -50
                            to: myImage.y - 150
                            duration: 150
                            easing.type: Easing.OutQuad
                        }

                        NumberAnimation {
                            target: myText
                            property: "opacity"
                            from: 1.0
                            to: 0.0
                            duration: 200
                            easing.type: Easing.Linear
                        }
                    }


            MediaPlayer {
                id: playMusic
                source: "qrc:/img/beng.mp3"
                audioOutput: AudioOutput {}
            }

            Image {
                id: myImage
                source: "qrc:/img/fash01.png" // 替换为你的图片路径
                fillMode: Image.PreserveAspectFit
                MouseArea {
                    anchors.fill: parent
                    acceptedButtons: Qt.AllButtons
                    drag.target: myImage
                    drag.axis: Drag.XAndYAxis
                    // 鼠标右键被按下
                    onPressed: {
                        if (mouse.button === Qt.RightButton) {
                            // 显示上下文菜单
                            contextMenu.popup()
                        }
                    }
                    onReleased: {
                        if(mouse.button === Qt.LeftButton)
                        {
                            bounceAnimation.start()
                            playMusic.play()
                            moveAndFadeOut.running = true
                            myText.visible = true
                            myText.opacity = 1.0
                            counter += 1
                            console.log("Counter value:", counter)
                        }
                    }
                }
            }
            // 木鱼动画序列
            SequentialAnimation {

                id: bounceAnimation
                running: false // 默认不运行

                NumberAnimation {
                    target: myImage
                    properties: "y"
                    from: myImage.y
                    to: myImage.y - 20 // 向上移动一定距离
                    duration: 50 // 持续时间
                    easing.type: Easing.OutQuad
                }

                NumberAnimation {
                    target: myImage
                    properties: "y"
                    from: myImage.y - 20
                    to: myImage.y + 10 // 回到原点下方一点
                    duration: 50
                    easing.type: Easing.OutQuad
                }

                NumberAnimation {
                    target: myImage
                    properties: "y"
                    from: myImage.y + 10
                    to: myImage.y // 回到原点
                    duration: 50
                    easing.type: Easing.OutQuad
                }
            }

            Text {
                id: countText
                text: "总功德:"+counter;
                visible: true
                opacity: 1.0
                font.pointSize: 12
                color:"#001d26"
                wrapMode: Text.WordWrap
                width: parent.width
                horizontalAlignment: Text.AlignHCenter
                x:myImage.x
                y:myImage.y + 200
            }

            // 定义上下文菜单
            Menu {
                id: contextMenu

                MenuItem {
                    text: "桃木鱼"
                    onTriggered: {
                        // 替换图片源
                        myImage.source = "qrc:/img/fash01.png"
                    }
                }
                MenuItem {
                    text: "黄木鱼"
                    onTriggered: {
                        // 替换图片源
                        myImage.source = "qrc:/img/fash02.png"
                    }
                }
                MenuItem {
                    text: "棕木鱼"
                    onTriggered: {
                        // 替换图片源
                        myImage.source = "qrc:/img/fash03.png"
                    }
                }
                MenuItem {
                    text: "紫檀木鱼"
                    onTriggered: {
                        // 替换图片源
                        myImage.source = "qrc:/img/fash04.png"
                    }
                }
                MenuItem {
                    text: "退出"
                    onTriggered: {
                         Qt.quit();
                    }
                }
            }


        }

}
